$(function () {
    // csrf_token
    function csrfSafeMethod(method) {
        return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));   
    }

    $.ajaxSetup({
        beforeSend: function (xhr, settings) {
            if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken'));
            }
        }
    });
    // 点击删除按钮
    $('.del_btn').click(function () {
        var del_nid = $(this).attr('nid');
        var del_url = $(this).attr('href');
        delcfm(nid=del_nid, url=del_url);
        return false;
    });
});

// 显示删除对话框
function delcfm(nid,url) {
    $('#del_url').val(url);
    $('#del_nid').val(nid);
    $('#delcfmModel').modal();
}
// 确认删除
$('#del_submit').click(function () {
    var del_url = $("#del_url").val();//获取会话中的隐藏属性URL
    var del_nid = $("#del_nid").val();
    $.ajax({
        url: del_url,
        type: 'POST',
        data: {'nid': del_nid},
        dataType: 'JSON',
        success: function (res) {
            location.reload();
        },
        error: function () {
            alert('网络繁忙，请稍候重试');
        }
    });
});